﻿<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />



    <link rel="stylesheet" href="../content/css/font.css">
    <link rel="stylesheet" href="../content/css/xadmin.css">
    <link rel="stylesheet" href="../content/plugin/bootstrap/css/bootstrap.min.css">
    <link rel='stylesheet' href='../content/plugin/bootstrap/css/style.css' />

    <script src="../content/js/jquery-1.10.2.min.js"></script>

    <script type="text/javascript" src="../content/js/xadmin.js"></script>
    <script type="text/javascript" src="../content/js/cookie.js"></script>
    <script src="../content/lib/layui/layui.js" charset="utf-8"></script>





</head>

<body>
    <div id="app">
        <div class="x-nav">

            <span class="nav-header">
                <a href="">首页</a>>
                <a href="">系统管理</a>>
                <a>
                    <cite>菜单管理</cite>
                </a>
            </span>

        </div>
        <div class="x-body">
            <div class="layui-row">
            
                <input type="text" name="username" placeholder="请输入菜单名称" v-model="search.textstr" autocomplete="off"
                    style="height:30px;width: 100px;">
                <input type="text" name="username" placeholder="请输入值内容" v-model="search.valuestr" autocomplete="off"
                    style="height:30px;width: 100px;">


                <button class="layui-btn" v-on:click="getdata"><i class="layui-icon">&#xe615;</i></button>


            </div>
            <hr />
            <div>

                <button class="layui-btn" v-on:click="add"><i class="layui-icon"></i>添加</button>

            </div>
            <hr/>
            <div class="table-responsive">
                <table class="table table-bordered table-hover">
                    <thead>
                        <tr>
    
    
                            <th>菜单标题</th>
                            <th>图标</th>
                            <th>值</th>
                            <th>地址</th>
                            <th>排序</th>
    
                            <th>操作</th>
    
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="uitem in arrayData">
    
    
                            <td>{{uitem.textstr}}</td>
                            <td>{{uitem.imgurlsrc}}</td>
                            <td>{{uitem.valuestr}}</td>
                            <td>{{uitem.nvaurl}}</td>
                            <td>{{uitem.seq}}</td>
    
                            <td class="td-manage">
                                <a title="编辑" v-on:click="peizhi(uitem)" href="javascript:;">
                                    功能配置
                                </a>
                                <a title="编辑" v-on:click="vupdate(uitem)" href="javascript:;">
                                    <i class="layui-icon"></i>
                                </a>
                                <a title="删除" v-on:click="vdel(uitem)" href="javascript:;">
                                    <i class="layui-icon">&#xe640;</i>
                                </a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
   
            <div class="page">
                <div>
                    <vue-nav :cur="search.page" :all="all" :allcount="allcount" :callback="callback"></vue-nav>
                </div>
            </div>

        </div>


        <!--添加-->
        <div class="modal fade" id="addbox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">添加信息</h4>
                    </div>
                    <div class="modal-body">
                        <fieldset>

                            <div class="control-group">
                                <label for="input01" class="control-label">菜单名称</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="addobj.textstr">
                                </div>
                            </div>

                            <div class="control-group">
                                <label for="input01" class="control-label">值</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="addobj.valuestr">
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">上级菜单</label>
                                <div class="controls">
                                    <select v-model="addobj.parentid" class="form-control">
                                        <option value="0">
                                            请选择
                                        </option>
                                        <option v-for="item in menulist" :value='item.id'>
                                            {{item.textstr}}
                                        </option>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">图标</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="addobj.imgurlsrc">
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">地址</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="addobj.nvaurl">
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">排序</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="addobj.seq">
                                </div>
                            </div>

                            <div class="control-group">
                                <label for="input01" class="control-label">是否启用</label>
                                <div class="controls">
                                    <select v-model="addobj.state" class="form-control">
                                        <option value="">
                                            请选择
                                        </option>
                                        <option v-for="item in statelist" :value='item.id'>
                                            {{item.name}}
                                        </option>
                                    </select>
                                </div>
                            </div>



                        </fieldset>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" v-on:click="insert(addobj)">确认</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--添加结束-->
        <!--修改-->
        <div class="modal fade" id="editbox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">修改信息</h4>
                    </div>
                    <div class="modal-body">
                        <fieldset>

                            <div class="control-group">
                                <label for="input01" class="control-label">菜单名称</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="editobj.textstr">
                                </div>
                            </div>

                            <div class="control-group">
                                <label for="input01" class="control-label">值</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="editobj.valuestr">
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">上级菜单</label>
                                <div class="controls">
                                    <select v-model="editobj.parentid" class="form-control">
                                        <option value="0">
                                            请选择
                                        </option>
                                        <option v-for="item in menulist" :value='item.id'>
                                            {{item.textstr}}
                                        </option>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">图标</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="editobj.imgurlsrc">
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">地址</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="editobj.nvaurl">
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">排序</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="editobj.seq">
                                </div>
                            </div>

                            <div class="control-group">
                                <label for="input01" class="control-label">是否启用</label>
                                <div class="controls">
                                    <select v-model="editobj.state" class="form-control">
                                        <option value="">
                                            请选择
                                        </option>
                                        <option v-for="item in statelist" :value='item.id'>
                                            {{item.name}}
                                        </option>
                                    </select>
                                </div>
                            </div>

                        </fieldset>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" v-on:click="update(editobj)">确认</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--修改结束-->

        <div class="modal fade" id="peizhibox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">功能配置</h4>
                    </div>
                    <div class="modal-body">
                        <fieldset>
                            <table class="layui-table">
                                <thead>
                                    <tr>

                                        <th>功能名称</th>
                                        <th>编码</th>

                                        <th>操作</th>

                                    </tr>
                                </thead>

                                <tbody>
                                    <tr v-for="uitem in datalist">
                                        <td>
                                            <input type="text" v-model="uitem.name" />
                                        </td>
                                        <td>
                                            <input type="text" v-model="uitem.code" />
                                        </td>

                                        <td class="td-manage">
                                            <a title="删除" v-on:click="delcode(uitem)" href="javascript:;">
                                                <i class="layui-icon">&#xe640;</i>
                                            </a>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>


                        </fieldset>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" @click="addhang">增加一行</button>
                            <button type="button" class="btn btn-default" @click="save">保存</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--修改结束-->


    </div>
    <link href="../content/plugin/sweetalert/sweetalert.css" rel="stylesheet">
    <script src="../content/plugin/sweetalert/sweetalert.min.js"></script>
    <script src="../content/plugin/bootstrap/js/bootstrap.min.js"></script>
    <script src="../content/js/vue2.js"></script>
    <script src="../content/js/vue-nav.js"></script>
    <script src="../content/js/config.js"></script>

    <script>

        Array.prototype.remove = function (val) {
            var index = this.indexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        };
        var vm = new Vue({
            el: "#app",
            data: {
                all: 0,
                search: {
                    page: 1,
                    size: 10
                },
                arrayData: [],
                allcount: 0,
                menulist: [],
                addobj: {
                    parentid: 0
                },
                editobj: {},
                datalist: [],
                statelist: [{ "id": 1, "name": "是" }, { "id": 0, "name": "否" }],
                typelist: [{ "id": "1", "name": "C端" }, { "id": "2", "name": "B端" }, { "id": "1,2", "name": "BC端" }],
            },
            components: {
                'vue-nav': Vnav
            },
            methods: {
                searchdata: function () {
                    this.search.page = 1;
                    this.getdata();
                },
                getmenulist: function (addobj) {
                    var self = this;

                    $.post(apiurl + "/admin/menu/list", { parentid: "0" }, function (data) {

                        self.menulist = data.data;

                    });
                },
                add: function () {
                    this.addobj = { parentid: 0 };
                    $("#addbox").modal('show');
                },
                addhang: function () {
                    if (this.datalist == null) {
                        this.datalist = [];
                    }
                    console.log("addhang", this.datalist);
                    var datalist = this.datalist;
                    datalist.push({});
                    this.datalist = datalist;
                },
                insert: function (addobj) {
                    var self = this;
                    addobj.id = "";
                    this.addobj.datalist = "";
                    //  this.addobj.token = json.token;
                    $.post(apiurl + "/admin/menu/add", addobj, function (data) {
                        if (data.status == 200) {
                            $("#addbox").modal('hide');
                            swal("success", "添加成功", "success");
                            self.getdata("");
                        } else {
                            swal("系统提示", data.message, "error");
                        }

                    });
                },
                delcode: function (uitem) {
                    var datalist = this.datalist;
                    datalist.remove(uitem);
                    this.datalist = datalist;
                },
                getdata: function (_keycontent) {  //查询数据

                    var self = this;
                    $.post(apiurl + "/admin/menu/list", this.search, function (_result) {
                        console.log(_result);
                        self.arrayData = _result.data;
                        self.all = _result.allcount;
                        self.allcount = _result.count;
                    });
                    this.getmenulist();
                },
                callback: function (data) {
                    var self = this;
                    this.search.page = data;
                    $.post(apiurl + "/admin/menu/list", this.search, function (_result) {
                        self.arrayData = _result.data;
                        self.all = _result.allcount;
                        self.allcount = _result.count;
                    });
                },
                vupdate: function (uitem) {

                    this.editobj = uitem;

                    console.log("haoqig", uitem);
                    $("#editbox").modal('show');

                },
                peizhi: function (uitem) {
                    this.editobj = uitem;
                    console.log("uitem.datalist", uitem.datalist);
                    if (uitem.datalist != "" && uitem.datalist != "undefined") {

                        this.datalist = JSON.parse(uitem.datalist);
                    } else {


                        this.datalist = [];
                    }


                    console.log("haoqig", uitem);
                    $("#peizhibox").modal('show');
                },
                update: function (uitem) {
                    var self = this;

                    $.post(apiurl + "/admin/menu/edit", uitem, function (data) {
                        if (data.status == 200) {
                            $("#editbox").modal('hide');
                            swal("success", "修改成功", "success");
                            self.getdata("");
                        } else {
                            swal("系统提示", data.message, "error");
                        }
                    });

                },
                vdel: function (uitem) {
                    var self = this;
                    swal({
                        title: "确定要删除吗?",
                        text: "",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "是",
                        cancelButtonText: '否',
                        closeOnConfirm: false
                    }, function () {


                        $.ajax({
                            url: apiurl + '/admin/menu/del',
                            type: 'DELETE',
                            data: { "ids": uitem.id },
                            success: function (result) {
                                if (result.status == 200) {
                                    swal("系统提示", "已删除", "success");
                                    self.getdata("");
                                } else {
                                    swal("系统提示", "系统异常", "success");
                                }
                            }
                        });

                    });
                },
                save: function () {
                    var self = this;

                    this.editobj.datalist = JSON.stringify(this.datalist);
                    this.editobj.token = json.token;
                    $.post(apiurl + "/admin/menuadd", this.editobj, function (data) {
                        if (data.status == 200) {
                            $("#peizhibox").modal('hide');
                            swal("success", "修改成功", "success");
                            self.getdata("");
                        } else {
                            swal("系统提示", data.message, "error");
                        }
                    });
                }

            },
            created: function () {  //初始化事件里边去调用查询方法
                this.getdata("");



            }
        });


    </script>
</body>

</html>